<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"></meta>
    <title>AdminLTE 2 | Dashboard</title>
</head>
<body>
<div class="controlDevice" th:fragment="controlDevice">

    <div class="bottombar"><!-- <img
                src="/icons/smoke.svg"/> -->
        <div class="bottombar-item selected" id="smokeDetectorBtn"><span class="bottombar-icon"><span></span>   </span><span class="name-tip">烟感</span><cite class="tip-alarm">0</cite></div>
        <div class="bottombar-item" id="streetLampBtn"><span class="bottombar-icon"><span></span></span><span class="name-tip">路灯</span><cite class="tip-alarm">0</cite>
        </div>
        <div class="bottombar-item" id="manholeCoverBtn"><span class="bottombar-icon"><span></span></span><span class="name-tip">窨井盖</span><cite class="tip-alarm">0</cite></div>
        <div class="bottombar-item" id="cameraBtn"><span class="bottombar-icon"><span></span></span><span class="name-tip">摄像头</span></div>
        <div class="bottombar-item" id="trashBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">垃圾桶</span></div>
        <div class="bottombar-item" id="gasSensingBtn"><span class="bottombar-icon"><span></span></span><span class="name-tip">气感</span></div>
        <div class="bottombar-item" id="humitureBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">温湿度</span><cite class="tip-alarm">0</cite></div><!-- 温感 -->
        <!-- <div class="bottombar-item" id=""><span class="bottombar-icon"><span></span><img src="/icons/humidity.svg"/></span><span
                class="name-tip">湿度</span></div> -->
        <div class="bottombar-item" id="geomagnetismBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">地磁</span></div>
        <div class="bottombar-item" id="fireplugBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">消防栓</span></div>
        <div class="bottombar-item" id="vehicleBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">车辆定位</span></div>
        <div class="bottombar-item" id="billboardBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">广告牌</span></div>
        <div class="bottombar-item" id="bridgeBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">桥梁</span></div>
        <div class="bottombar-item" id="personnelBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">人员</span></div>
        <div class="bottombar-item" id="waterLevel"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">水位测定</span></div>
        <div class="bottombar-item" id="sewageBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">污水检测</span></div>
        <div class="bottombar-item" id="virescenceBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">绿化</span></div>
        <div class="bottombar-item" id="sprayBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">喷淋</span></div>
        <div class="bottombar-item" id="electricityBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">电流</span></div>
        <div class="bottombar-item" id="guideCardBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">引导牌</span></div>
        <div class="bottombar-item" id="PM25Btn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">PM2.5</span></div>
        <div class="bottombar-item" id="GPSBtn"><span class="bottombar-icon"><span></span></span><span
                class="name-tip">GPS</span></div>
                
        <div class="bottombar-sprite"></div>
        <div class="bottombar-all">
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
    <script>
    $(".bottombar-item").hide();
	var deviceTypeIdArr = [];
    $.ajax({
        url: "/orgdev/devicetype/count",
        type: "GET",
        async: false,
        success: function (result) {
            if (result.status == "200") {
              var data = result.data;
                for(var i=0;i<data.length;i++){
                    deviceTypeIdArr.push(data[i][0].deviceTypeId)
                  if(data[i][0].deviceTypeId == "001"){
                    $("#smokeDetectorBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "002"){
                    $("#gasSensingBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "003"){
                    $("#cameraBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "004"){
                    $("#streetLampBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "005"){
                    $("#manholeCoverBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "006"){
                    $("#trashBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "007"){
                    $("#humitureBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "008"){
                    $("#geomagnetismBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "009"){
                    $("#fireplugBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "010"){
                    $("#vehicleBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "011"){
                    $("#billboardBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "012"){
                    $("#bridgeBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "013"){
                    $("#personnelBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "014"){
                    $("#waterLevel").show();
                  }
                  if(data[i][0].deviceTypeId == "015"){
                    $("#sewageBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "016"){
                    $("#virescenceBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "017"){
                    $("#sprayBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "018"){
                    $("#electricityBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "019"){
                    $("#guideCardBtn").show();
                  }
                  if(data[i][0].deviceTypeId == "020"){
                    $("#PM25Btn").show();
                  }
                  if(data[i][0].deviceTypeId == "021"){
                    $("#GPSBtn").show();
                  }
                  
                }
            } else {

            }
        }

    });
        //初始化设备类型为烟感
        var devType = "smokeDetector";
        //devType = "manholeCover";
        //devType = "streetLamp";
        //devType = "camera";
        var devTypeId = "001";
        var devHeader = "smokeHeader";
        $(".bottombar").attr("devType", devType);
        //页面初始化搜索功能实现
        searchFunc(devHeader);

        //点击按钮取消闪烁
        $('.smokeHeader .historyBgc').on('click', function () {
            $('.smokeHeader .historyBgc .historyMsg').removeAttr("id", "twinkle");
        });
        $('.manholeCoverHeader .historyBgc').on('click', function () {
            $('.manholeCoverHeader .historyBgc .historyMsg').removeAttr("id", "coverTwinkle");
        });
        //未选中状态清除设备相关信息
        function hideDevFunc() {
            $(".searchBox input").each(function (i, item) {
                $(this).val("")
            });
            //清除地图上所有覆盖物
            //devStatus = null;
            devType = null;
            devTypeId = null;
            devHeader = null;
            $(".bottombar").removeAttr("devType");
            BaiDuMap.removeOverlay();
            //隐藏头部公共部分
            $(".navbar-custom-menu").hide();
            //移除右部侧边栏
            $(".control-sidebar").removeClass("control-sidebar-open");
            $(".bottombar").removeAttr("devType");
            //隐藏烟感报警弹出框
            $(".alertWarningContent").hide();
            //隐藏井盖报警弹出框
            $(".manholeCoverWarningContent").hide();

          $(".humitureWarningContent").hide();
            //清除报警声音
            stopSound();
        }
    function smokeTipAlarmFunc(){
      //烟感——如果设备切换按钮有数字则显示，否则隐藏
        if (maxWarningSum > 0) {
          $("#smokeDetectorBtn .tip-alarm").show();
        } else{
          $("#smokeDetectorBtn .tip-alarm").hide();
        }
    }
    function coverTipAlarmFunc() {
      //井盖
       $(".manholeCoverWarningContent").hide();
        $("#manholeCoverBtn .tip-alarm").text(coverMaxWarningSum);
        if (coverMaxWarningSum > 0) {
            $("#manholeCoverBtn .tip-alarm").show();
          $('.manholeCoverHeader .historyBgc .historyMsg').attr("id", "coverTwinkle");
        } else {
            $("#manholeCoverBtn .tip-alarm").hide();
            $('.manholeCoverHeader .historyBgc .historyMsg').removeAttr("id", "coverTwinkle");
        }
    }

    function humitureTipAlarmFunc() {
      //井盖
       $(".humitureWarningContent").hide();
        $("#humitureBtn .tip-alarm").text(humitureMaxWarningSum);
        if (humitureMaxWarningSum > 0) {
            $("#humitureBtn .tip-alarm").show();
          $('.humitureHeader .historyBgc .historyMsg').attr("id", "humitureTwinkle");
        } else {
            $("#humitureBtn .tip-alarm").hide();
            $('.humitureHeader .historyBgc .historyMsg').removeAttr("id", "humitureTwinkle");
        }
    }
    //隐藏历史记录
    $(".messages-menu").on("click",function (){
    	$(".openPublicSidebar").removeClass("control-sidebar-open");
    });
    $(".smokeSum").on("click",function (){
    	$(".openPublicSidebar").removeClass("control-sidebar-open");
    });
        //页面加载完成后再点击 
        setTimeout(function () {
            var toggleFlag = null;
            
            //    烟感 —— 点击烟感按钮，控制烟感设备的显示和隐藏
            $("#smokeDetectorBtn").click(function () {
            	
            	
            	
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {
                        hideDevFunc();
                        //重新渲染烟感设备
                        if (!$("#smokeDetectorBtn.selected").length) {
                        	//-----------------
                        	/* 历史中只显示烟感特有的 */
                         	$(".openPublicSidebar").addClass("smokeCharts");
                        	//大数据切换
                        	$(".contorl-sidebar-halfheight-top").hide();
                        	$(".control-sidebar-halfheight").hide();
                        	//假的大数据
                        	//$(".dataStatistics").show();
                        	$(".dataStatistics").hide();
                        	//真的大数据
                        	$(".data").show();
                        	
                            renderSmoke();
                            devType = "smokeDetector";
                            devTypeId = "001";
                            devHeader = "smokeHeader";
                            $(".bottombar").attr("devType", "smokeDetector");
                            //devStatus = "smokeDetectorStatus";
                            $(".smokeHeader").show();
                            //页面初始化渲染未处理数据，报警弹出框
                            if ($(".header-notice span").text() > 0) {
                                $(".alertWarningContent").show();
                            }
                            //隐藏设备切换按钮
                            //$("#smokeDetectorBtn .tip-alarm").hide();
                            
                            //获取设备数量
                            getDeviceSum();
                            /* 显示火警报警条数  */
                            getAlarmNum();
                            /* 显示故障信息条数 */
                            getFaultNum();
                            /* 低电信息条数 */
                            getLowPowerNum();
                            /* 报警信息下拉框 */
                            alarmFaultLow();
                            searchFunc(devHeader);
                            if ($("#smokeDetectorBtn .tip-alarm").text() > 0) {
                              $('.smokeHeader .historyBgc .historyMsg').attr("id", "twinkle");
                            } else {
                                $('.smokeHeader .historyBgc .historyMsg').removeAttr("id", "twinkle");
                            }
                        }
                        	setTimeout(function (){
                        		toggleFlag = null;
                        	},1000)
                        //设备按钮选中状态的切换
                        $this.toggleClass("selected").siblings().removeClass("selected");

                        
                    }, 0);
                }
            });

            //   路灯 —— 点击路灯按钮，控制路灯设备的显示和隐藏
            $("#streetLampBtn").click(function () {
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {

                        hideDevFunc();
                        if (!$("#streetLampBtn.selected").length) {
                        	$(".openPublicSidebar").removeClass("smokeCharts");
                        	$(".contorl-sidebar-halfheight-top").show();
                        	$(".control-sidebar-halfheight").show();
                        	$(".dataStatistics").hide();
                        	$(".data").hide();
                            //获取灯开启和关闭的数量
                            /*            var LampSum;
                             var lampOnNum;
                             var lampOffNum; */
                            devType = "streetLamp";
                            devTypeId = "004";
                            devHeader = "streetLampHeader";
                            //devStatus = "streetLampStatus";
                            $(".bottombar").attr("devType", "streetLamp");
                            //显示路灯设备
                            $(".streetLampHeader").show();
                            renderStreetLamp();
                            //渲染灯的数量
                            getLampSwitchNum();
                            lampBtnSumFunc();
                            searchFunc(devHeader);
                        }
                        $this.toggleClass("selected").siblings().removeClass("selected");

                        toggleFlag = null;
                    }, 0);
                }
            });
            //   窨井盖 —— 点击窨井盖按钮，控制设备的显示和隐藏manholeCoverWarningInit
            $("#manholeCoverBtn").click(function () {
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {
                        hideDevFunc();
                        if (!$("#manholeCoverBtn.selected").length) {
                        	$(".openPublicSidebar").removeClass("smokeCharts");
                        	$(".contorl-sidebar-halfheight-top").show();
                        	$(".control-sidebar-halfheight").show();
                        	$(".dataStatistics").hide();
                        	$(".data").hide();
                            devType = "manholeCover";
                            devTypeId = "005";
                            devHeader = "manholeCoverHeader";
                            
                            //页面初始化渲染未处理数据，报警弹出框
                            if ($(".coverNotice span").text() > 0) {
                                $(".manholeCoverWarningContent").show();
                                //manholeCoverWarningInit();
                            } else{
                              $(".manholeCoverWarningContent").hide();
                            }
                            //隐藏设备切换按钮
                            //$("#manholeCoverBtn .tip-alarm").hide();
                            
                            //devStatus = "manholeCoverStatus";
                            $(".bottombar").attr("devType", "manholeCover");
                            //显示窨井盖设备
                            $(".manholeCoverHeader").show();
                            renderManholeCover();
                            coverNumFunc();

                            searchFunc(devHeader);
                            if ($("#manholeCoverBtn .tip-alarm").text() > 0) {
                              $('.manholeCoverHeader .historyBgc .historyMsg').attr("id", "coverTwinkle");
                            } else {
                                $('.manholeCoverHeader .historyBgc .historyMsg').removeAttr("id", "coverTwinkle");
                            }
                        }
                        $this.toggleClass("selected").siblings().removeClass("selected");
                        toggleFlag = null;
                    }, 0);
                }
            });

            //摄像头 camera
            $("#cameraBtn").click(function () {
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {

                        hideDevFunc();
                        if (!$("#cameraBtn.selected").length) {
                        	$(".openPublicSidebar").removeClass("smokeCharts");
                        	$(".contorl-sidebar-halfheight-top").show();
                        	$(".control-sidebar-halfheight").show();
                        	$(".dataStatistics").hide();
                        	$(".data").hide();
                            devTypeId = "003";
                            devType = "camera";
                            devHeader = "cameraHeader";
                            //devStatus = "cameraStatus";
                            $(".bottombar").attr("devType", "camera");
                            //显示摄像头设备
                            $(".cameraHeader").show();
                            //地图上渲染摄像头数据
                            renderCamera();
                            searchFunc(devHeader);
                        }
                        $this.toggleClass("selected").siblings().removeClass("selected");
                        toggleFlag = null;
                    }, 0);
                }
            });
            
            //   垃圾桶
            $("#trashBtn").click(function () {
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {
                        hideDevFunc();
                        if (!$("#trashBtn.selected").length) {
                        	$(".openPublicSidebar").removeClass("smokeCharts");
                        	$(".contorl-sidebar-halfheight-top").show();
                        	$(".control-sidebar-halfheight").show();
                        	$(".dataStatistics").hide();
                        	$(".data").hide();
                            devType = "trash";
                            devTypeId = "006";
                            devHeader = "trashHeader";
                            //devStatus = "manholeCoverStatus";
                            $(".bottombar").attr("devType", "trash");
                            //显示窨井盖设备
                            $(".trashHeader").show();
                            renderTrash();
                            trashNumFunc();

                            searchFunc(devHeader);
                        }
                        $this.toggleClass("selected").siblings().removeClass("selected");
                        toggleFlag = null;
                    }, 0);
                }
            });
            //   温湿度 humitureBtn
            $("#humitureBtn").click(function () {
                var $this = $(this);
                if (toggleFlag != null) {
                    clearTimeout(toggleFlag);
                    toggleFlag = null;
                } else {
                    toggleFlag = setTimeout(function () {
                        hideDevFunc();
                        if (!$("#humitureBtn.selected").length) {
                        	$(".openPublicSidebar").removeClass("smokeCharts");
                        	$(".contorl-sidebar-halfheight-top").show();
                        	$(".control-sidebar-halfheight").show();
                        	$(".dataStatistics").hide();
                        	$(".data").hide();
                            devType = "humiture";
                            devTypeId = "007";
                            devHeader = "humitureHeader";
                            //页面初始化渲染未处理数据，报警弹出框
                            if ($(".humitureNotice span").text() > 0) {
                                $(".humitureWarningContent").show();
                                //manholeCoverWarningInit();
                            } else{
                              $(".humitureWarningContent").hide();
                            }
                            //devStatus = "manholeCoverStatus";
                            $(".bottombar").attr("devType", "humiture");
                            //显示窨井盖设备
                            $(".humitureHeader").show();
                            renderHumiture();
                            humitureNumFunc();

                            searchFunc(devHeader);
                        }
                        $this.toggleClass("selected").siblings().removeClass("selected");
                        toggleFlag = null;
                    }, 0);
                }
            }); 
            
            //     气感 —— 点击气感按钮，控制气感设备的显示和隐藏
            /*  $("#gasSensingBtn").click(function () {
             hideDevFunc();
             if(!$("#gasSensingBtn.selected").length){
             //显示气感设备

             }
             $(this).toggleClass("selected").siblings().removeClass("selected");
             }); */
             //烟感——如果有警报则按钮闪烁
             if ($("#smokeDetectorBtn .tip-alarm").text() > 0) {
              $('.smokeHeader .historyBgc .historyMsg').attr("id", "twinkle");
             } else {
                 $('.smokeHeader .historyBgc .historyMsg').removeAttr("id", "twinkle");
             }


             //初始化时根据设备显示最开始展示的设备
             for(var i=0;i<deviceTypeIdArr.length;i++){

                 if(deviceTypeIdArr[i] == "001"){
             		//获取设备数量
             		getDeviceSum();
             		/* 显示火警报警条数  */
             		getAlarmNum();
             		/* 显示故障信息条数 */
             		getFaultNum();
             		/* 低电信息条数 */
             		getLowPowerNum();
             		/* 报警信息下拉框 */
             		alarmFaultLow();
                  $(".smokeHeader").show();
                  renderSmoke();
                  //页面初始化渲染未处理数据，报警弹出框
                  if ($(".header-notice span").text() > 0) {
                      $(".alertWarningContent").show();
                  }
     				$("#smokeDetectorBtn").addClass("selected").siblings().removeClass("selected");
                  searchFunc(devHeader);
                  if ($("#smokeDetectorBtn .tip-alarm").text() > 0) {
                    $('.smokeHeader .historyBgc .historyMsg').attr("id", "twinkle");
                  } else {
                      $('.smokeHeader .historyBgc .historyMsg').removeAttr("id", "twinkle");
                  }
     				return false;
                 }else if(deviceTypeIdArr[i] == "004"){
     	   				//hideDevFunc();
     	 	            //获取灯开启和关闭的数量
     	 	            devType = "streetLamp";
     	 	            devTypeId = "004";
     	 	            devHeader = "streetLampHeader";
     	 	            $(".bottombar").attr("devType", "streetLamp");
     	 	            //显示路灯设备
     	 	            $(".streetLampHeader").show();
     	 	            renderStreetLamp();
     	 	            //渲染灯的数量
     	 	            getLampSwitchNum();
     	 	            lampBtnSumFunc();
     	 	            searchFunc(devHeader);
     	 				$("#streetLampBtn").addClass("selected").siblings().removeClass("selected");
     	 				return false;
                 } 
                 
               }
        }, 100);

        

    </script>
</div>
</body>
</html>

